<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  
  
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>
    
    Hexo</title>
  
  <link rel="shortcut icon" href="/favicon.ico">
  
  
<link rel="stylesheet" href="/css/style.css">

  
  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<script src="/js/pace.min.js"></script>

<meta name="generator" content="Hexo 5.2.0"></head>

<body>
  <main class="content">
    <section class="outer">
  <article id="post-CentOS7.5安装Mysql" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    

    
    <div class="article-meta">
      <a href="/2020/12/16/CentOS7.5%E5%AE%89%E8%A3%85Mysql/" class="article-date">
  <time datetime="2020-12-16T03:04:21.688Z" itemprop="datePublished">2020-12-16</time>
</a>
      
    </div>
    

    
    
<div class="tocbot"></div>

    

    <div class="article-entry" itemprop="articleBody">
      
      
      
      <h3 id="1、安装前，我们可以检测系统是否自带安装-MySQL"><a href="#1、安装前，我们可以检测系统是否自带安装-MySQL" class="headerlink" title="1、安装前，我们可以检测系统是否自带安装 MySQL"></a>1、安装前，我们可以检测系统是否自带安装 MySQL</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep mysql</span><br></pre></td></tr></table></figure>

<p>什么都没有出现证明没有安装过</p>
<h3 id="2、下载mysql5-7-rpm源"><a href="#2、下载mysql5-7-rpm源" class="headerlink" title="2、下载mysql5.7 rpm源"></a>2、下载mysql5.7 rpm源</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm</span><br></pre></td></tr></table></figure>

<h3 id="3、安装mysql源"><a href="#3、安装mysql源" class="headerlink" title="3、安装mysql源"></a>3、安装mysql源</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum localinstall mysql57-community-release-el7-8.noarch.rpm</span><br></pre></td></tr></table></figure>

<h3 id="4、安装mysql源"><a href="#4、安装mysql源" class="headerlink" title="4、安装mysql源"></a>4、安装mysql源</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh mysql57-community-release-el7-8.noarch.rpm</span><br></pre></td></tr></table></figure>

<h3 id="5、安装mysql"><a href="#5、安装mysql" class="headerlink" title="5、安装mysql"></a>5、安装mysql</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install mysql-server</span><br></pre></td></tr></table></figure>

<h3 id="6、查看版本号"><a href="#6、查看版本号" class="headerlink" title="6、查看版本号"></a>6、查看版本号</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -V</span><br></pre></td></tr></table></figure>

<h3 id="7、运行Mysql"><a href="#7、运行Mysql" class="headerlink" title="7、运行Mysql"></a>7、运行Mysql</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysqld start</span><br></pre></td></tr></table></figure>

<h3 id="8、Mysql是否运行"><a href="#8、Mysql是否运行" class="headerlink" title="8、Mysql是否运行"></a>8、Mysql是否运行</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysqld status</span><br></pre></td></tr></table></figure>

<h3 id="9、停止Mysql"><a href="#9、停止Mysql" class="headerlink" title="9、停止Mysql"></a>9、停止Mysql</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysqld stop</span><br></pre></td></tr></table></figure>

<h3 id="10、重启Mysql"><a href="#10、重启Mysql" class="headerlink" title="10、重启Mysql"></a>10、重启Mysql</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysqld restart</span><br></pre></td></tr></table></figure>

<h3 id="11、Mysql5-7默认安装之后root是有密码的，所以我们现在要先获取密码"><a href="#11、Mysql5-7默认安装之后root是有密码的，所以我们现在要先获取密码" class="headerlink" title="11、Mysql5.7默认安装之后root是有密码的，所以我们现在要先获取密码"></a>11、Mysql5.7默认安装之后root是有密码的，所以我们现在要先获取密码</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep <span class="string">&quot;password&quot;</span> /var/<span class="built_in">log</span>/mysqld.log</span><br></pre></td></tr></table></figure>

<h3 id="12、用默认账号root，和上面获取的密码登陆mysql"><a href="#12、用默认账号root，和上面获取的密码登陆mysql" class="headerlink" title="12、用默认账号root，和上面获取的密码登陆mysql"></a>12、用默认账号root，和上面获取的密码登陆mysql</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -uroot -p<span class="string">&#x27;你的密码&#x27;</span></span><br></pre></td></tr></table></figure>

<h3 id="13、重置密码"><a href="#13、重置密码" class="headerlink" title="13、重置密码"></a>13、重置密码</h3><p>密码需要带数字，大写字母，小写字母</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SET PASSWORD &#x3D; PASSWORD(&#39;你的密码&#39;);</span><br></pre></td></tr></table></figure>

<h3 id="14、设置密码永不过期"><a href="#14、设置密码永不过期" class="headerlink" title="14、设置密码永不过期"></a>14、设置密码永不过期</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ALTER USER &#39;root&#39;@&#39;localhost&#39; PASSWORD EXPIRE NEVER;</span><br></pre></td></tr></table></figure>

<h3 id="15、刷新MySQL的系统权限相关表"><a href="#15、刷新MySQL的系统权限相关表" class="headerlink" title="15、刷新MySQL的系统权限相关表"></a>15、刷新MySQL的系统权限相关表</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

<h3 id="16、设置允许外部远程访问"><a href="#16、设置允许外部远程访问" class="headerlink" title="16、设置允许外部远程访问"></a>16、设置允许外部远程访问</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grant all privileges on *.* to root@&quot;%&quot; identified by &quot;你的密码&quot;;</span><br></pre></td></tr></table></figure>

<h3 id="17、再次刷新MySQL的系统权限相关表"><a href="#17、再次刷新MySQL的系统权限相关表" class="headerlink" title="17、再次刷新MySQL的系统权限相关表"></a>17、再次刷新MySQL的系统权限相关表</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2020/12/16/CentOS7.5%E5%AE%89%E8%A3%85Mysql/" data-id="ckj9ggdrc00005yfy1kai0esq" class="article-share-link">
        Share
      </a>
      
    </footer>

  </div>

  
  
<nav class="article-nav">
  
  <a href="/2020/12/16/CentOS7.5%E6%90%AD%E5%BB%BAsftp%E6%9C%8D%E5%8A%A1/" class="article-nav-link">
    <strong class="article-nav-caption">Newer</strong>
    <div class="article-nav-title">
      
      (no title)
      
    </div>
  </a>
  
  
  <a href="/2020/12/15/ContOS7.5%E5%AE%89%E8%A3%85Redis/" class="article-nav-link">
    <strong class="article-nav-caption">Older</strong>
    <div class="article-nav-title"></div>
  </a>
  
</nav>

  

  
  
  
  

</article>
</section>
    <footer class="footer">
  <div class="outer">
    <div class="float-right">
      <ul class="list-inline">
  
  <li><i class="fe fe-smile-alt"></i> <span id="busuanzi_value_site_uv"></span></li>
  
  <li><i class="fe fe-bookmark"></i> <span id="busuanzi_value_page_pv"></span></li>
  
</ul>
    </div>
    <ul class="list-inline">
      <li>Hexo &copy; 2020</li>
      
        <li>京ICP备17054916号-2</li>
      
      <li>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></li>
      <li>theme  <a target="_blank" rel="noopener" href="https://github.com/zhwangart/hexo-theme-ocean">Ocean</a></li>
    </ul>
  </div>
</footer>
  </main>
  <aside class="sidebar">
    <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/hexo.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">Home</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">Archives</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/gallery">Gallery</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">About</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link nav-item-search" title="Search">
        <i class="fe fe-search"></i>
        Search
      </a>
    </li>
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      <div class="totop" id="totop">
  <i class="fe fe-rocket"></i>
</div>
    </li>
    <li class="nav-item">
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="fe fe-feed"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
  </aside>
  
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>





<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
  });
</script>



<script src="/js/ocean.js"></script>

</body>

</html>